/*
 * File Name: AbstractBasePanel.java
 */

package co.edu.uniandes.intercon.client.gui;

import java.awt.Component;
import java.awt.Dimension;

import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 * Groups general behaivour for the panels of the application
 * 
 * @author Fabian Gutierrez [fagossa@gmail.com]
 */
@SuppressWarnings("serial")
public abstract class AbstractBasePanel extends JPanel {
    // TODO implement F1 functionality
    
    protected static final String MSG_NO_RECORDS_FOUND = 
            " Search complete, no matches found";
    
    protected static final String MSG_OCURRENCES_FOUND = 
            " ocurrence(s) found";
    
    protected JFrame parent;
    
    /**
     * Applies the rendered specified
     * 
     * @param table     Table that contains the column where the renderer is 
     *                  going to be applied
     * @param renderer  CellRenderer to be applied
     */
    protected void addColorRendererToTable( final JTable table, 
                                            final TableCellRenderer renderer) {        
        int columns = table.getColumnModel().getColumnCount();
        for (int i = 0; i<columns; i++) {
            table.getColumnModel().getColumn(i).setCellRenderer(renderer);
        }
    }
    
    /**
     * Applies the rendered specified
     * 
     * @param table     Table that contains the column where the renderer is 
     *                  goingto be applied
     * @param column    Column where the renderer will be applied
     * @param renderer  CellRenderer to be applied
     */
    protected void addImageRendererToTable( 
                                final JTable table, //table
                                final int column, //column to apply the renderer
                                final TableCellRenderer renderer) {
        table.getColumnModel().getColumn(column).setCellRenderer(renderer);
    }
        
    /**
     * Adds a space between the components
     * 
     * @return a <code>space</code> component
     */
    protected static Component spaceBetween() {
        return Box.createRigidArea(new Dimension(2, 0));
    }

    /**
     * Sets the parent window to the current panel
     * 
     * @param frame window to be added as the parent of the current panel
     */
    public void setParentWindow(JFrame frame) {
        this.parent = frame;        
    }
}
